package cn.yunhe.servlet;

import cn.yunhe.dao.IHuiFuDao;
import cn.yunhe.dao.impl.HuiFuDao;
import cn.yunhe.entity.Admin;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

public class ReplyServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        HttpSession session = request.getSession();
        PrintWriter out = response.getWriter();


        String context = request.getParameter("context");
        Admin admin = (Admin) session.getAttribute("admin");
        int fid = admin.getUid();
        int lid = Integer.parseInt(request.getParameter("lid"));

        IHuiFuDao huiFuDao = new HuiFuDao();
        if (huiFuDao.addHuiFu(context, lid, fid)) {
            out.print("<script>alert('回复成功!!!');location.href='LiuYanListServlet'</script>");
        } else {
            out.print("<script>alert('回复失败,请联系管理员!!!');location.href='LiuYanListServlet'</script>");
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
